package com.southminority.ethnic.controller.coures;

import com.southminority.ethnic.common.result.R;
import com.southminority.ethnic.pojo.CourseTeacher;
import com.southminority.ethnic.service.course.CourseTeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "课程教师", description = "课程教师相关接口")
@RestController
@RequestMapping("/api/course/teacher")
@CrossOrigin
@Validated
public class CouresTeacherController{
    @Autowired
    private CourseTeacherService courseTeacherService;
    //根据教师id查询教师
    @Operation(summary = "根据教师id查询教师")
    @GetMapping("/{id}")
    public R<CourseTeacher> getTeacherById(@PathVariable @NotNull(message = "教师id不能为空") Long id){
        try {
            return R.ok(courseTeacherService.getById(id));
        } catch (Exception e) {
            log.error("根据教师id查询教师失败", e);
            return R.fail("查询失败：" + e.getMessage());
        }

    }
    @GetMapping("/test")
    @Operation(summary = "测试", description = "测试接口")
    public R<String> test() {
        try {
            log.info("测试");
            return R.ok("测试成功");
        } catch (Exception e) {
            log.error("测试失败", e);
            return R.fail(e.getMessage());
        }
    }

}
